import type { PartialConsult, ConsultIllness } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { ConsultType } from '@/enums'

export const useConsultStore = defineStore('cp-consult', () => {
  // 1.根据创建订单的接口得知我们需要定义问诊状态:就诊类型、极速问诊类型、科室、病情、患者id、优惠券id
  const consult = ref<PartialConsult>({})
  // 2.修改就诊类型
  const setType = (type: ConsultType) => consult.value.type = type
  // 3.修改极速问诊类型
  const setIllnessType = (type: 0 | 1) => consult.value.illnessType = type
  // 4.修改科室
  const setDepId = (depId: string) => consult.value.depId = depId
  // 5.修改病情描述相关信息
  const setIllness = (illness: ConsultIllness) => {
    consult.value.illnessDesc = illness.illnessDesc
    consult.value.illnessTime = illness.illnessTime
    consult.value.consultFlag = illness.consultFlag
    consult.value.pictures = illness.pictures
  }
  // 6.修改患者
  const setPatientId = (patientId: string) => consult.value.patientId = patientId
  // 7.设置优惠券id
  const setCouponId = (couponId: string) => consult.value.couponId = couponId
  // 8.清空记录:当订单生成了，那么本地保存的患者数据要清除掉
  const clearConsult = () => consult.value = {}
  return {
    consult,
    setType,
    setIllnessType,
    setDepId,
    setIllness,
    setPatientId,
    setCouponId,
    clearConsult
  }
}, { persist: true })